package com.ruoyi.pcwl.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.pcwl.domain.Carousel;
import com.ruoyi.pcwl.domain.query.CarouselQuery;

import com.ruoyi.pcwl.domain.vo.Result;
import com.ruoyi.pcwl.service.CarouselItemService;
import com.ruoyi.pcwl.service.CarouselService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 轮播图信息 Controller
 */
@Api(tags = "轮播图信息控制层")
@RestController("carouselController")
@RequestMapping("/carousel")
public class CarouselController extends BaseController{

	@Resource
	private CarouselService carouselService;

	@Resource
	private CarouselItemService carouselItemService;
	/**
	 * 根据条件分页查询
	 */
	@ApiOperation("根据条件分页查询")
	@GetMapping("/loadDataList")
	public Result loadDataList(CarouselQuery query){
		return Result.ok(carouselService.selectPage(query));
	}

	/**
	 * 新增
	 */
	@ApiOperation("新增")
	@PostMapping("/add")
	public Result add(@RequestBody Carousel bean) {
		carouselService.add(bean);
		return Result.ok(null);
	}

	/**
	 * 批量新增
	 */
	@ApiOperation("批量新增")
	@PostMapping("/addBatch")
	public Result addBatch(@RequestBody List<Carousel> listBean) {
		carouselService.addBatch(listBean);
		return Result.ok(null);
	}

	/**
	 * 批量新增/修改
	 */
	@ApiOperation("批量新增/修改")
	@PostMapping("/addOrUpdateBatch")
	public Result addOrUpdateBatch(@RequestBody List<Carousel> listBean) {
		carouselService.addBatch(listBean);
		return Result.ok(null);
	}

	/**
	 * 根据Id查询对象
	 */
	@ApiOperation("根据Id查询对象")
	@GetMapping("/getCarouselById/{id}")
	public Result getCarouselById(@PathVariable Long id) {
		return Result.ok(carouselService.getCarouselById(id));
	}

	/**
	 * 根据Id修改对象
	 */
	@ApiOperation("根据Id修改对象")
	@PutMapping("/updateCarouselById/{id}")
	public Result updateCarouselById(@RequestBody Carousel bean,@PathVariable Long id) {
		carouselService.updateCarouselById(bean);
		return Result.ok(null);
	}

	/**
	 * 根据Id删除
	 */

	@ApiOperation("根据Id删除")
	@DeleteMapping("/deleteCarouselById/{id}")
	public Result deleteCarouselById(@PathVariable Long id) {
		carouselService.deleteCarouselById(id);
		carouselItemService.deleteByCarouselId(id);
		return Result.ok(null);
	}

	/**
	 * 发布轮播到小程序首页
	 */
	@ApiOperation("小程序首页轮播发布")
//    @PreAuthorize("@ss.hasPermi('system:article:list')")
	@PutMapping("/publishSyCarousel/{id}")
	public AjaxResult publishSyCarousel(@PathVariable("id") Long id) throws WxErrorException {
		carouselService.publishSyCarousel(id);
		return AjaxResult.success();
	}

	/**
	 * 根据Id查询对象
	 */
	@ApiOperation("获取全部轮播分类")
	@GetMapping("/getCarouselCategory")
	public Result getCarouselCategory() {
		List<Carousel> categoryList=carouselService.getCarouselCategory();
		return Result.ok(categoryList);
	}


}
